﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using DrugStore.Models;
using DrugStore.Helper;
using System.Web.Services.Description;
using DrugStore.Exceptions;

namespace DrugStore.Controllers
{
    public class ProductController : Controller
    {
        ProductBussiness objBussiness;
        //
        // GET: /Product/

        public ActionResult Index(int page=0)
        {
                const int pageSize = 5;
                objBussiness = new ProductBussiness();
                PaginateList<Product> products = objBussiness.GetAllProducts(page, pageSize);
                return View(products);            
        }

        //Return the product.
        public ActionResult Detail(String id) 
        {
            Message message = new Message();
            try 
            {
                Guid productId = Guid.Empty;
                if(!Guid.TryParse(id,out productId))
                {
                    throw new ParameterInvalidException("","Don't exist this product");
                }

                objBussiness = new ProductBussiness();
                ProductModel product = objBussiness.GetProductByProductId(id);
                return View(product);
            }
            catch (System.Exception ex) 
            {
                ViewData["Message"] = ex.Message;
            }
            return null;                  
        }

        public ActionResult Edit(String id) 
        {            
            return View();
        }

        [HttpPost]
        public ActionResult Edit(String id,FormCollection fromValues) 
        {            
            return View();
        }        
    }
}
